﻿//using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Text;
//using System.Drawing;
//using System.Drawing.Imaging;

//namespace LowLevelGraphics.Filter
//{
//    public class ImagePlus
//    {
//    }

//    //TODO: windowed sinc filter, implement and test
//    /// <summary>
//    /// 
//    /// </summary>
//    public class WindowedSinc : BaseImageFilter
//    {
//        int winSize = 24; //window size
//        double fc = 0.5; //cutoff frequency
//        bool showFilter;
//        int width, height;

//        /// <summary>
//        /// default constructor
//        /// </summary>
//        public WindowedSinc()
//        {
//        }

//        /// <summary>
//        /// used by clone to create a deep copy
//        /// </summary>
//        /// <param name="_windowedSinc"></param>
//        internal WindowedSinc(WindowedSinc _windowedSinc)
//        {
//            this.winSize = _windowedSinc.winSize;
//            this.fc = _windowedSinc.fc;
//            this.showFilter = _windowedSinc.showFilter;
//        }

//        /// <summary>
//        /// Execute this Filter
//        /// A Debug Statement is written if a concrete Filter is called
//        /// </summary>
//        /// <param name="_bitmap"></param>
//        /// <returns></returns>
//        public override UnsafeBitmap Execute(UnsafeBitmap _bitmap)
//        {
//            ImagePlus imp = null; //_bitmap;
//            /*if (imp == null || imp.getStackSize() == 1 || imp.getBitDepth() != 8)
//            {
//                IJ.error("This plugin requires an 8-bit stack");
//                return;
//            }
//            convolveFrames(imp, winSize, 0.5 * fc);*/
//            return _bitmap;
//        }

//        /// <summary>
//        /// Convolves the frames.
//        /// </summary>
//        /// <param name="imp">The imp.</param>
//        /// <param name="winSize">Size of the win.</param>
//        /// <param name="fc">The fc.</param>
//        protected void convolveFrames(ImagePlus imp, int winSize, double fc)
//        {
//            double PI = Math.PI;
//            double[] h = new double[(winSize + 1)];
//            double sumh = 0;
//            int i;
//            for (i = 0; i <= winSize; i++)
//            {
//                if (i == winSize / 2)
//                {
//                    h[i] = 2 * PI * fc;
//                }
//                else
//                {
//                    h[i] = Math.Sin(2 * PI * fc * (i - winSize / 2)) / (i - winSize / 2);
//                }
//                h[i] = h[i] * (0.54 - 0.46 * Math.Cos(2 * PI * i / winSize));
//                //IJ.log(i+"\t"+h[(int)i]);
//                sumh += h[i];
//            }

//            /*if (showFilter)
//            {
//                double[] xValues = new double[winSize + 1];
//                for (i = 0; i <= winSize; i++)
//                    xValues[i] = i;
//                PlotWindow plot = new PlotWindow("Filter Kernel", "Time", "", xValues, h);
//                plot.draw();
//            }*/

//            width = imp.getWidth();
//            height = imp.getHeight();
//            int nSlices = imp.getStackSize();
//            ImageStack bis = imp.getStack();

//            ByteProcessor bip = (ByteProcessor)bis.getProcessor(1);
//            FloatProcessor fip = new FloatProcessor(width, height);
//            float[] fpixels = (float[])fip.getPixels();
//            ImageStack ois = new ImageStack(width, height);

//            for (int j = winSize; j < nSlices; j++)
//            {
//                //IJ.showStatus("Processing " + j + "/" + nSlices + "");
//                //IJ.showProgress(j, nSlices - 1);
//                for (i = 0; i <= winSize; i++)
//                {
//                    bip = (ByteProcessor)bis.getProcessor(j - i + 1);
//                    byte[] bpixels = (byte[])bip.getPixels();
//                    for (int x = 0; x < width; x++)
//                    {
//                        for (int y = 0; y < height; y++)
//                        {
//                            int k = width * y + x;
//                            if (i == 0)
//                                fpixels[k] = 0;
//                            fpixels[k] += (float)(bpixels[k] & 0xff) * h[i] / sumh;
//                        }
//                    }
//                }
//                ImageProcessor tip = fip.convertToByte(false);
//                ois.addSlice("", tip);
//                //ois.addSlice("", fip.duplicate()); 
//            }
//            return;
//        }

//        /// <summary>
//        /// used to create a deep copy
//        /// </summary>
//        /// <returns></returns>
//        public override object Clone()
//        {
//            return new WindowedSinc(this);
//        }
//    }
//}
